﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WJP.Dependency;
using WJP.Logging;

namespace WJP.Configuration
{
    /// <summary>
    /// 配置类
    /// </summary>
    public class Configuration
    { 
        /// <summary>
        /// 配置类实例，通过Create方法创建
        /// </summary>
        public static Configuration Instance { get; private set; }

        private Configuration() { }

        /// <summary>
        /// 创建配置
        /// </summary>
        /// <returns></returns>
        public static Configuration Create()
        {
            if(Instance != null)
                Instance = new Configuration();
            return Instance;
        }

        public Configuration SetDefault<TService, TImplementer>(string serviceName = null, DependencyLifeStyle life = DependencyLifeStyle.Singleton)
            where TService : class
            where TImplementer : class, TService
        {
            throw new NotImplementedException("未实现依赖注入。");
        }
        public Configuration SetDefault<TService, TImplementer>(TImplementer instance, string serviceName = null)
            where TService : class
            where TImplementer : class, TService
        {
            throw new NotImplementedException("未实现依赖注入。");
        }

        /// <summary>
        /// 注册组件
        /// </summary>
        /// <returns></returns>
        public Configuration RegisterCommonComponents()
        {
            //TODO:注册组件
            return this;
        }

        public Configuration RegisterUnhandledExceptionHandler()
        {
            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
            {
                LogManager.Logger.ErrorFormat("Unhandled exception: {0}", e.ExceptionObject);
            };
            return this;
        }
    }
}
